$(function(){
    $.fn.reset = function(){
        $(this).each(function(){
            this.reset();
        });
    }
    $.fn.disabled = function(disabled){
        if(disabled) $(this).attr("disabled", "-1");
        else $(this).removeAttr("disabled");
    }
    $.fn.loader = function(visible){
        var s = $(this);
		
        if(!visible){
            $('#IDLoadCropIcon').fadeIn("medium", function(){
                $(this).remove();
            });
            $('#IDLoadCrop').fadeIn("medium", function(){
                $(this).remove();
            });
            return;
        }
		
        s.prepend('<div id="IDLoadCrop"></div>');
        s.prepend('<div id="IDLoadCropIcon"><img src="./Resouces/images/loader-icon.gif" align="absmiddle" width="16" height="16" /><span>Chargement..</span></div>');
		
        var idText = $('#IDLoadCropIcon');
        var idLoad = $('#IDLoadCrop');
		
        idLoad.css({
            width: s.width()+'px',
            height: s.height()+'px',
            opacity: (40/100)
        });
        idText.css({
            marginLeft: (s.width() / 2) - (idText.width() / 2) + "px",
            marginTop: (s.height() / 2) - (idText.height() / 2) + "px"
        });
		
        idLoad.focus().select();
    }
	
    var modes = {
        None: 0, 
        Insert: 1, 
        Update: 3, 
        Delete: 2
    }
	
    $.extend({
        isAtach: false,
        isMode: modes.None,
        id: 0,
        heightMin: 55,
        image: null,
        isLoader: false,
        formValidator: null,
        formLogos: $("#frmLogos"),
        popup: $("#JLModalLogos"),
        UIEditLogos: $("#IDLogosNew"),
        UILogos: $("#IDLogos"),
        UICrop: $("#IDCrop"),
        cboplanches: $("#cboplanches"),
        cboplanchelogo: $("#cboplanchelogo"),
        uploader: $("#fileUpload"),
        grid: $("#jqGrid"),
        sortable: $("#IDSortable"),
        init: function(){
            var s = this;
            s.addBindEvents();
            s.initDragBoxes();
            s.initGrid();
            s.UIEditLogos.hide();
            s.setValidator();
            s.makeUploader( '/csme.fr/images/logos', '15091456', false, false );
            s.UICrop.hide();
            s.loadPlanches();
            s.loadLogosByPart( 0 );
        },
        addBindEvents: function(){
            var s = this;
			
            // MAIN PLANCHES
            $("#sinsert").bind("click", function(e){
                s.id = 0;
                s.isMode = modes.None;
                s.makePopup();
            });
            $("#sinsert-nouveau").bind("click", function(e){
                s.newPlanche();
            });
            $("#sinsert-supprimer").bind("click", function(e){
                s.deletePlanche();
            });
            s.cboplanches.bind("change", function(e){
                s.loadLogosByPart( $(this).val(), true);
            });
					
            // LOGOS
            $("#idHide").bind("click", function(e){
                s.sortLogos();
                s.popup.JLModal.close();
            });
            $("#sUIInsert").bind("click", function(e){
                s.id = 0;
                s.isMode = modes.Insert;
                $('#lbl-okfile').hide();
                s.isAtach = false;
                s.newUILogos();
            });
            $("#sUIUpdate").bind("click", function(e){
                s.isMode = modes.Update;
                s.id = 0;
                var id = s.grid.jqGrid('getGridParam','selrow');
                if(id){
                    var row = s.grid.jqGrid('getRowData', id);
                    s.id = row.int_id_logo;
                    s.editUILogos(s.id);
                }else 
                    alert("Avertissement\nVeuillez s\u00E9lectionner le logo \u00E0 modifier.");
            });
            $("#sUIDelete").bind("click", function(e){
                s.isMode = modes.Update;
                s.id = 0;
                var id = s.grid.jqGrid('getGridParam','selarrrow');
				
                if(id != ""){
                    /*var row = s.grid.jqGrid('getRowData', id);
					s.id = row.int_id_logo;*/
                    s.removeLogo(id);
                }else 
                    alert("Avertissement\nVeuillez s\u00E9lectionner le(s)logo(s) \u00E0 effacer.");
            });
			
            $("#btn-cancel").bind("click", function(e){
                s.isAtach = false;
                if(s.image) s.image.data = null;
                s.visibilityUILogos(false);
            });
            $("#cboplanches").bind("change", function(e){
                //s.visibilityUILogos(false);
                });
            $("#idAnnuler").bind("click", function(e){
                s.removeCrop();
            });
            s.formLogos.bind("submit", function(e){
                if(s.isMode == modes.Insert){
                    if(!s.formLogos.valid()){
                        if($("#txtlien").val()=="http://") $("#txtlien").val("");
                    }
                    s.saveInsertLogo();
                }
                if(s.isMode == modes.Update){
                    s.saveUpdateLogo();
                }
                return false;
            });
            $("#idCouper").bind("click", function(e){
                if(!s.isLoader){
                    if(s.isSelectedCrop()){
                        s.visibleLoader(true);
                        s.setCropImage();
                    }
                    else{
                        alert("S\u00E9lectionner la zone de recadrage.");
                    }
                }
            });
        },
		
        // PLANCHES
        loadPlanches: function(){
            var s = $;
            s.cboplanches.empty();
            s.cboplanches.append( s.getOption("", "Chargement..", true) );
            s.cboplanches.disabled(true);
			
            s.cboplanchelogo.empty();
            s.cboplanchelogo.append( s.getOption("", "Chargement..", true) );
            s.cboplanchelogo.disabled(true);
			
            $.post("./?ws=Partenaires&act=getPartenaires", {}, function(data){
                if(data != null && data != ""){
                    $.each(data, function(i){
                        var obj = data[i];
                        s.cboplanches.append(s.getOption(obj.id_int_partenaire, obj.int_page, false));
                        s.cboplanchelogo.append(s.getOption(obj.id_int_partenaire, obj.int_page, false));
                    });
					
                    s.cboplanches.find("option:selected").text("S\u00E9lectionner...");
                    s.cboplanches.disabled(false);
					
                    s.cboplanchelogo.find("option:selected").text("S\u00E9lectionner...");
                    s.cboplanchelogo.disabled(false);
                }
            }, "json");
        },
        getOption: function(value, label, selected){
            selected = (selected) ? "selected=\"selected\"" : "";
            return "<option value=\"" + value + "\" " + selected + ">" + label + "</option>";
        },
        newPlanche: function(){			
            if(confirm("D\u00E9sirez-vous cr\u00E9er une nouvelle planche?")){
                var s = this;
                // NEW PLANCHE
                $("#IDModules").loader(true);
                $.post("./?ws=Partenaires&act=addPartenaires", {
                    time: new Date().getTime()
                },
                function(data){
                    if(data != ""){
                        alert(data);
                        $("#IDModules").loader(false);
                        s.cboplanches.disabled(false);
                        s.loadPlanches();
                        s.selectCombo(s.cboplanches, "");
                        s.loadLogosByPart( "", true);
                    }
                });
				
            };
        },
        deletePlanche: function(){
            var s = this;
			
            if(s.cboplanches.val() != ""){
                s.cboplanches.focus().select();
                var text = s.cboplanches.find("option:selected").text();
                if(confirm("D\u00E9sirez-vous \u00E9liminer la planche " + text)){
                    // DELETE PLANCHE
                    var t = s.sortable.find("li").length;
                    if(t<1){
                        $("#IDModules").loader(true);
                        $.post("./?ws=Partenaires&act=removePartenaires", {
                            id: s.cboplanches.val(), 
                            time: new Date().getTime()
                        }, 
                        function(data){
                            if(data != ""){
                                alert(data);
                                $("#IDModules").loader(false);
                                s.cboplanches.disabled(false);
                                s.loadPlanches();
                                s.selectCombo(s.cboplanches, "");
                                s.loadLogosByPart( "", true);
                            }
                        });
                    }else{
                        alert("Avertissement!\nDes logos sont pr\u00E9sents sur cette planche. Vous devez supprimer tous les logos ou les r\u00E9affecter sur une autre planche.");
                    }
                }
            }
            else{
                alert("S\u00E9lecionnez une planche.");
                s.cboplanches.focus().select();
            }
        },
        noPlanches: function(){
            return "<table id=\"IDMsgNoLogos\" width=\"100%\" height=\"100%\"><tr><td align=\"center\" valign=\"middle\">Aucun logos sur la planche s&eacute;lectionn&eacute;e.</td></tr></table>";
        },
        loadLogosByPart: function(id, b){
            var s = $;
            var d = $("#IDDrag");
			
            s.sortable.hide();
            s.sortable.empty();
			
            $("#IDMsgNoLogos").remove();
			
            if(id=="" || id==0){
                d.append(s.noPlanches());
                return;
            }
			
            $("#IDMsgNoLogos").remove();
            s.cboplanches.disabled(true);
			
            if(b) $("#IDModules #IDModulesContent").loader(true);
			
            $.post("./?ws=Partenaires&act=getLogosByPart", {
                cboplanches: id, 
                time: new Date().getTime()
            },
            function(data){
                if(data != null && data != ""){
                    $.each(data, function(i){
                        var obj = data[i];
                        s.sortable.append( s.makeBoxLogo(obj.int_id_logo, obj.var_title, obj.var_src, obj.var_size) );
                    });
						
                    $("#IDModules").loader(false);
                    s.cboplanches.disabled(false);
                    s.sortable.fadeIn("fast");
                }
                else{
                    $("#IDModules").loader(false);
                    s.cboplanches.disabled(false);
                    $("#IDMsgNoLogos").remove();
                    d.append(s.noPlanches());
                }
            }, "json");
        },
        makeBoxLogo: function(id, title, src, size){
            var width = size.split("x");
            width = width[0];

            var li = $("<li/>").addClass("portlet").attr("code", id).css("width", width+"px");
            var header = $("<div/>").addClass("portlet-header");
            var icon = $("<span/>").addClass("ui-icon").addClass("ui-icon-arrow-4");
            var content = $("<div/>").addClass("content");
            var desc = $("<em/>").html( title );
            var controls = $("<div/>").addClass("controls").append("Logo:");
            var thumb = $("<img/>").addClass("thumb").attr("src", "../images/logos/thumbs/"+src+"?=rd"+new Date().getTime());
			
            li.append(header);
            header.append(icon);
            content.append(controls).append(desc).append("<br/>").append(thumb);
            li.append(content);
			
            return li;
        },
		
        // LOGOS
        makePopup: function(){
            var s = this;
            s.isMode = modes.None;
			
            //if(s.cboplanches.val() != "")
            s.popup.JLModal({
                opacity: 43,
                duration: 100,
                titleHTML: "Ajouter Logo",
                closeButton: false,
                escKey: false
            });
        /*else{
				s.cboplanches.focus();
				alert("S\u00E9lecionne le planche.");
				return;
			}*/
        },
        initDragBoxes: function(){
            var s = this;
            $(".column").sortable({
                stop: function(event, ui){
                    s.sortLogos();
                }
            });
			
            $(".column").disableSelection();
        },
        sortLogos: function(){
            var s = this;
            var i = 1;
            var k = 0;
            var t = s.sortable.find("li").length;
            var data = "[";
			
            s.sortable.find("li").each(function(){
                data += "{\"id\": " + $(this).attr('code') + ", \"order\": " + i + "}, ";
                i++;			
            });
			
            data += "{\"id\": 0, \"order\": 0}]";
			
            if(i>1) $.post("./?ws=Logos&act=sortLogos", {
                data: data, 
                time:new Date().getTime()
            });
        },
        initGrid: function(){
            var s = this;
            s.grid.jqGrid({
                // <MODIFICAR>
                url: './Queries/query-logos.php?nd=' + new Date().getTime(),
                colNames:['int_id_logo', 'Logo', 'Titre', 'Publi&eacute;', 'Taille', 'Planche', 'Etat'],
                colModel:[
                {
                    hidden:true, 
                    search:false, 
                    name:'int_id_logo', 
                    index:'int_id_logo', 
                    align:'left'
                },

                {
                    name:'var_src', 
                    index:'var_src', 
                    align:'left', 
                    sortable:false, 
                    formatter:s.formatImage
                },

                {
                    name:'var_title', 
                    index:'var_src', 
                    align:'left'
                },

                {
                    name:'dat_creation', 
                    index:'dat_creation', 
                    align:'left'
                },

                {
                    name:'var_size', 
                    index:'var_size', 
                    align:'center'
                },

                {
                    name:'int_page', 
                    index:'int_page', 
                    align:'left', 
                    formatter:s.formatPlanche
                },

                {
                    name:'var_htmldesc', 
                    index:'var_htmldesc', 
                    align:'left'
                }
                ],
                sortname: ['int_id_logo'],
                sortorder: "desc",
                width: 700,
                height: 300,
                rownumbers: true,
                // </MODIFICAR>	
                loadtext: 'Chargement...',
                datatype: "json",
                pager: $('#jqpager'),
                rowNum: 20,
                rowList:[10, 20, 50],	
                viewrecords: true,
                multiselect: true
            });
        },
        formatImage: function(cellvalue, options, rowObject){
            return "<img src=\"../images/logos/thumbs/" + cellvalue + "?nd=" + new Date().getTime() + "\" height=\"24\" />";
        },
        formatPlanche:  function(cellvalue, options, rowObject){
            return "<b> Planche " + cellvalue + "</b>";
        },
        makeUploader: function(_folder, _sizeLimit, _multi, photos){
            var s = this;
            s.uploader.uploadify({
                uploader   : './Resouces/js/uploader_new/uploadify.swf',
                script     : './Resouces/js/uploader_new/uploadify.php',
                cancelImg  : './Resouces/js/uploader_new/cancel.png',
                folder     : _folder,
                /*scriptData : {mywork: $.idd},
				queueID    : 'IDFile',*/
                buttonText : 'Parcourir',
                fileDesc   : 'Format de l\'image *.jpg uniquement.',
                fileExt	   : '*.jpg',
                sizeLimit  : _sizeLimit,
                auto       : true,
                multi      : _multi,
                onSelectOnce: function(event, data){
                    $("#btn-save").attr("disabled", "-1");
                    $("#btn-cancel").attr("disabled", "-1");
                    $('#lbl-okfile').hide();
                },
                onCancel: function(event, queueID, file, data){
                    s.iconError(true, "S&eacute;lectionnez une image");
                    s.isAtach = false;
                    $("#btn-save").removeAttr("disabled");
                    $("#btn-cancel").removeAttr("disabled");
                },
                onComplete: function(event, queueID, fileObj, response, data){
                    $("#btn-save").removeAttr("disabled");
                    $("#btn-cancel").removeAttr("disabled");
                    
                    console.log(response);
                    
                    s.image = {
                        name: fileObj.name, 
                        path: "../images/logos/" + fileObj.name, 
                        obj: null,
                        tSize: null,
                        size: null,
                        data: null
                    };
                },
                onAllComplete: function(event, data){
                    s.visibilityUILogosCrop(true);
                    s.loadImage(s.image.path);
                },
                onError: function(event, queueSizeLimit){
                    s.iconError(true, "S&eacute;lectionnez une image");
                    s.isAtach = false;
                    $("#btn-save").removeAttr("disabled");
                    $("#btn-cancel").removeAttr("disabled");
                }
            });
        },
        loadImage: function(path){			
            $("#IDCropArea").hide();
			
            var s = this;
            s.visibleLoader(true);
			
            $(new Image()).load(function(){
                $('#IDPhoto').append(this);
                s.makeCrop(this);
            }).error(function(){ 
                alert("Erreur de chargement de l'image.");
            }).attr('src', s.image.path + '?rnd' + new Date().getTime());
        },
        visibleLoader: function(visible){
            var s = this;
			
            if(!visible){
                $('#IDLoadCropIcon').remove();
                $('#IDLoadCrop').remove();
                s.isLoader = false;
                return;
            }

            var cont = $("#IDContent");
			
            cont.prepend('<div id="IDLoadCrop"></div>');
            cont.prepend('<div id="IDLoadCropIcon"><img src="./Resouces/images/loader-icon.gif" align="absmiddle" width="16" height="16" /><span>Chargement..</span></div>');
			
            var idText = $('#IDLoadCropIcon');
            var idLoad = $('#IDLoadCrop');
			
            idLoad.css({
                width: cont.width() + 'px',
                height: cont.height() + 'px',
                opacity: (60/100)
            });
            idText.css({
                marginLeft: (cont.width() / 2) - (idText.width() / 2) + "px",
                marginTop: (cont.height() / 2) - (idText.height() / 2) + "px"
            });
            s.isLoader = true;
            cont.focus().select();
        },
        iconError: function(_bool, _title){
            $('#lbl-okfile').css('display','none');
            var _icon = "";
            if(_bool) _icon = './Resouces/images/cancelfield.png';
            else _icon = './Resouces/images/okfield.png';
			
            $('#lbl-okfile').html('<img src="'+_icon+'" alt="'+_title+'" title="'+_title+'" />');
            $('#lbl-okfile').fadeIn();
        },
        setValidator: function(){
            var s = this;
            s.formValidator = s.formLogos.validate({
                event: "blur",
                rules:{ 
                    'txttitre': "required",
                    'txtdescription': "required",
                    'txtlien': {
                        url:true
                    },
                    'cboplanchelogo': "required",
                    'cboetat': "required"
                },
                messages:{
                    'txttitre': "Entrez votre titre.",
                    'txtdescription': "Entrez votre description.",
                    'txtlien': "Entrez votre lien.",
                    'cboplanchelogo': "S&eacute;lectionnez l'planche.",
                    'cboetat': "S&eacute;lectionnez l'&eacute;tat."
                }
            });
        },
        selectCombo: function(combo, value){
            combo.find("option").each(function(){
                if($(this).val() == value){
                    $(this).attr('selected', 'selected'); 
                }
            });
        },
        newUILogos: function(){
            var s = this;
            s.visibilityUILogos(true, true);
            $("#txtlien").val("http://");
        },
        editUILogos: function(id){
            var s = this;
			
            s.visibleLoader(true);
			
            $('#lbl-okfile').hide();
            s.isAtach = false;
            s.formValidator.resetForm();
			
            $.post("./?ws=Logos&act=getLogo", {
                id: id, 
                time: new Date().getTime()
            }, 
            s.onGetLogo, "json");
        },
        onGetLogo: function(data){
            var s = $;
            if(data != null && data != ""){
                $("#txttitre").val( data.txttitre );
                $("#txtdescription").val( data.txtdescription );
                $("#txtlien").val( data.txtlien );
				
                s.image = {
                    name: null, 
                    path: null, 
                    obj: null,
                    tSize: null,
                    size: null,
                    data: {
                        name: data.name, 
                        size: data.size
                    }
                };
				
                s.iconError(false, "Image ajout&eacute;.");
                s.selectCombo( $("#cboetat"), data.cboetat );
                s.selectCombo( s.cboplanchelogo , data.cboplanchelogo );
							
                s.UIEditLogos.find("#txttitre").focus().select();
                s.visibilityUILogos(true, false);
                s.visibleLoader(false);
            }
            else alert("Avertissement\nNe peut enregistrer vos donn\u00E9es.");
        },
        makeCrop: function(image){
            var s = this;
            s.image.obj = $(image);
            s.image.obj.css({
                border:'none',
                padding:0,
                margin:0
            }).attr("id","IDImageCrop");
			
            ///var size = s.resizeToHeight(s.image.obj.attr("width"), s.image.obj.attr("height"), s.heightMin);
            s.image.tSize = {
                width:s.image.obj.attr("width"), 
                height: s.image.obj.attr("height")
            };
            //alert("width:"+ s.image.tSize.width+", height:"+ s.image.tSize.height);
			
            s.image.obj.imgAreaSelect({ 
                //minWidth: size.width,
                minHeight: s.heightMin,
                //aspectRatio: size.width + ':' + size.height,
                //onSelectChange: s.onPreview,
                onSelectEnd: s.onSelectEnd, 
                handles: true,
                parent: '#IDPhoto'
            });
			
            $('#IDPreview').empty();
            /*var ss = $('<img src="' + s.image.path+'" style="position: relative;" />');
			$('#IDPreview').append(ss).css({
				width: size.width + 'px',
				height: size.height + 'px'
			});*/
			
            s.visibleLoader(false);
            $("#IDCropArea").show();
        },
        resizeToHeight: function(rWidth, rHeight, height){
            var ratio = height / rHeight;
            var width = Math.round(rWidth * ratio);
            return {
                width: width, 
                height: height
            };
        },	
        resizeToWidth: function(rWidth, rHeight, width){
            var ratio = width / rWidth;
            var height = Math.round(rHeight * ratio);
            return {
                width: width, 
                height: height
            };
        },
        onPreview: function(img, selection){
            var image = $(img);
            $.image.tSize.width
            var scaleX = $.image.tSize.width / (selection.width || 1);
            var scaleY = $.image.tSize.height / (selection.height || 1);
		  			
            $('#IDPreview img').css({
                width: Math.round(scaleX * image.width()) + 'px',
                height: Math.round(scaleY * image.height()) + 'px',
                marginLeft: '-' + Math.round(scaleX * selection.x1) + 'px',
                marginTop: '-' + Math.round(scaleY * selection.y1) + 'px'
            });
        },
        onSelectEnd: function(img, selection){
            $.image.size = selection;
        },
        isSelectedCrop: function(){
            var s = this;
            b = false;
            if(s.image && s.image.size){
                b = true;
            }
            return b;
        },
        removeCrop: function(){
            var s = this;
            $('#IDPhoto').empty();
            s.image.obj.empty();
            s.image.obj.remove();
            $('#IDPreview').empty();
            s.visibilityUILogosCrop(false);
        },
        setCropImage: function(){
            var s = this;
            var i = this.image;
            var id = "";
            if(s.isMode == modes.Update) id = s.id;

            $.post("./?ws=Logos&act=crop", {
                x1: i.size.x1, 
                y1: i.size.y1, 
                width: i.size.width, 
                height: i.size.height, 
                name: i.name, 
                id: id, 
                time: new Date().getTime()
            }, 
            s.onFinishedCropImage, "json");
        },
        onFinishedCropImage: function(data){
            var s = $;
            if(data != null && data != ""){
                s.image.data = data;
                s.isAtach = true;
                s.visibleLoader(false);
                s.removeCrop();
                s.iconError(false, "Image ajout&eacute;.");
            }
            else{
                alert("ERROR!!");
            }
        },
        saveInsertLogo: function(){
            var s = this;			
            if(s.formLogos.valid()){
                if(s.isAtach){
                    s.visibleLoader(true);
                    var data = s.image.data;					
                    $.post("./?ws=Logos&act=addLogo", {
                        txttitre: $("#txttitre").val(), 
                        txtdescription: $("#txtdescription").val(), 
                        txtlien: $("#txtlien").val(), 
                        cboetat: $("#cboetat").val(), 
                        cboplanchelogo: s.cboplanchelogo.val(),
                        name: data.name, 
                        size: data.size, 
                        time: new Date().getTime()
                    }, 
                    function(data){
                        if(data != ""){
                            alert(data);
                            s.visibleLoader(false);
                            s.visibilityUILogos(false);
                            s.grid.trigger('reloadGrid');
								
                            // update current planche
                            s.loadLogosByPart( s.cboplanches.val() );
                        }
                    });
                }
                else{
                    alert("S\u00E9lectionnez une image.");
                    s.iconError(true, "S&eacute;lectionnez une image");
                }
            }
        },
        saveUpdateLogo: function(){
            var s = this;
            if(s.formLogos.valid()){
                if(s.image.data){
                    s.visibleLoader(true);
                    var data = s.image.data;
                    $.post("./?ws=Logos&act=editLogo", {
                        id: s.id,
                        txttitre: $("#txttitre").val(),
                        txtdescription: $("#txtdescription").val(), 
                        txtlien: $("#txtlien").val(), 
                        cboetat: $("#cboetat").val(),
                        cboplanchelogo: s.cboplanchelogo.val(),
                        name: data.name, 
                        size: data.size, 
                        time: new Date().getTime()
                    }, 
                    function(data){
                        if(data != ""){
                            alert(data);
                            s.visibleLoader(false);
                            s.visibilityUILogos(false);
                            s.grid.trigger('reloadGrid');
								
                            // update current planche
                            s.loadLogosByPart( s.cboplanches.val() );
                        }
                    });
                }
                else{
                    alert("S\u00E9lectionnez une image.");
                    s.iconError(true, "S&eacute;lectionnez une image");
                }
            }
        },
        removeLogo: function(ids){
            var s = this;
			
            ids = "\"" + ids + ", 0\"";
			
            if(confirm("Voulez-vous vraiment effacer le(s) logo(s)?")){
                s.visibleLoader(true);
				
                $.post("./?ws=Logos&act=removeLogo", {
                    ids: ids, 
                    time: new Date().getTime()
                }, 
                function(data){
                    if(data != ""){
                        alert(data);
                        s.visibleLoader(false);
                        s.grid.trigger('reloadGrid');
                        // update current planche
                        s.loadLogosByPart( s.cboplanches.val() );
                    }
                });
            }
        },
        visibilityUILogos: function(visible, reset){
            var s = this;
			
            if(visible){
                s.UIEditLogos.show();
                if(reset) s.formLogos.reset();
                s.formValidator.resetForm();
                s.UIEditLogos.find("#txttitre").focus().select();
                s.UILogos.hide();
            }
            else{
                s.UIEditLogos.hide();
                s.UILogos.show();
                s.isMode = modes.None;
            }
        },
        visibilityUILogosCrop: function(visible){
            var s = this;
            $("#IDCropArea").hide();
            if(visible){
                $('#IDPhoto').empty();
                s.UICrop.show();
                s.UIEditLogos.hide();
            }
            else{
                $('#IDPhoto').empty();
                s.UICrop.hide();
                s.UIEditLogos.show();
            }
        }
    });
	
    $.init();
});